{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5]\n",
      "[1, 2, 3, 4, 5]\n",
      "[1, 2, 3, 4, 5]\n",
      "[5]\n"
     ]
    }
   ],
   "source": [
    "a = [ 1,2,3,4,5 ]\n",
    "print(a[0:])# [1, 2, 3, 4, 5]\n",
    "print(a[:])#  [1, 2, 3, 4, 5]\n",
    "print(a[:100])# [1, 2, 3, 4, 5]\n",
    "print(a[-1:])# [5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "\n",
    "\n",
    " elif  关键字是用于给 if 语句添加其他条件语句的\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "\n",
    "    假设你有一个变量 \"example\"，如何判断它的类型？\n",
    "\n",
    "'''\n",
    "\n",
    "example = \"adb\"\n",
    "type(example)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "example2 = 100\n",
    "type(example2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "exbmple \n",
      "\n",
      "example\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "     将字符串 \"example\" 中的字母 a 替换为字母 b，以下代码正确的是？\n",
    "\n",
    "'''\n",
    "\n",
    "str = 'example'\n",
    "result = str.replace('a','b')\n",
    "print(result,'\\n')\n",
    "print(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "\n",
    "        正确的读取一个文件  f = open(\"test.txt\", \"r\")。\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#   测验 - 操作符\n",
    "\n",
    "\n",
    "'''\n",
    "\n",
    "    1、3*1**3 表达式输出结果为 3\n",
    "    \n",
    "       解释： ** 拥有更高的优先级。\n",
    "       \n",
    "       \n",
    "       \n",
    "    2、9//2 表达式输出结果为 4\n",
    "    \n",
    "        解释：// 用于向下取接近除数的整数。\n",
    "        \n",
    "        \n",
    "        \n",
    "    3、以下代码输出结果为 yes\n",
    "    \n",
    "        x = True\n",
    "        y = False\n",
    "        z = False\n",
    "\n",
    "        if x or y and z:\n",
    "            print(\"yes\")\n",
    "        else:\n",
    "            print(\"no\")\n",
    "\n",
    "        解释：and 拥有更高优先级，会先行运算。\n",
    "        \n",
    "        \n",
    "        \n",
    "        \n",
    "        \n",
    "        优先级顺序为 NOT、AND、OR。\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a and b =  20\n",
      "c and b =  False\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "\n",
    "    运算符 ： and\tx and y\t布尔\"与\" - 如果 x 为 False，x and y 返回 False，否则它返回 y 的计算值。\n",
    "\n",
    "\n",
    "'''\n",
    "\n",
    "a = 10\n",
    "b = 20\n",
    "c = False\n",
    "\n",
    "print('a and b = ',a and b)\n",
    "print('c and b = ',c and b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c =  10\n",
      "e =  20\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "\n",
    "  运算符 or  x or y    布尔\"或\"\t- 如果 x 是非 0，它返回 x 的值，否则它返回 y 的计算值。\n",
    "\n",
    "'''\n",
    "\n",
    "\n",
    "a = 10\n",
    "b = 20\n",
    "c = a or b\n",
    "print('c = ', c)#  返回 a的值 10\n",
    "\n",
    "d = False\n",
    "\n",
    "e = d or b\n",
    "print('e = ',e)# 返回 b的值 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "not a :  False\n",
      "not b :  True\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "\n",
    "    运算符 not\tnot x\t布尔\"非\" - 如果 x 为 True，返回 False 。如果 x 为 False，它返回 True。\n",
    "\n",
    "\n",
    "'''\n",
    "\n",
    "a = True\n",
    "\n",
    "b = False\n",
    "\n",
    "print('not a : ',not a)\n",
    "\n",
    "print('not b : ',not b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "letter ==  p\n",
      "letter ==  t\n",
      "letter ==  h\n",
      "letter ==  n\n",
      "4\n",
      "['p', 't', 'h', 'n']\n",
      "li[0] =  p\n",
      "li[1] =  t\n",
      "li[2] =  h\n",
      "li[3] =  n\n"
     ]
    }
   ],
   "source": [
    "li = []\n",
    "str = \"python\"\n",
    "for letter in str:\n",
    "    if letter == 'o':\n",
    "        continue\n",
    "    elif letter == 'y':\n",
    "        continue\n",
    "    else:\n",
    "        li.append(letter)\n",
    "        print('letter == ',letter)\n",
    "        \n",
    "        \n",
    "print (len(li))\n",
    "print(li)\n",
    "for index in range(len(li)):\n",
    "    print('li[%s] = '% index ,li[index])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个小于1000的数10\n",
      "primeLi :  [2, 3, 5, 7]\n",
      "primPairCount =  2\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "    num = input('请输入一个小于1000的数')\n",
    "\n",
    "    TypeError: 'str' object cannot be interpreted as an integer\n",
    "    \n",
    "    input读取的类型是str（字符串），需要转换成int类型\n",
    "    \n",
    "'''\n",
    "num = int( input('请输入一个小于1000的数'))\n",
    "\n",
    "def isPrime(num):\n",
    "    for i in range(2,num):\n",
    "        if num % i == 0:\n",
    "            return False\n",
    "    else:\n",
    "            return True\n",
    "\n",
    "primeLi = [i for i in range(2,num)  if isPrime(i)]\n",
    "print('primeLi : ',primeLi)\n",
    "primPairCount = 0\n",
    "for item1 in primeLi:\n",
    "    for item2 in primeLi:\n",
    "        if item1 + item2 == num and item1 <= item2:\n",
    "            primPairCount +=1\n",
    "            \n",
    "print('primPairCount = ',primPairCount)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
